/**
 * 试卷管理 试卷列表
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>试卷列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="paper-search">
      <el-form-item label="搜索：">
        <el-input size="small" v-model="formInline.paperName" placeholder="输入试卷名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-select size="small" v-model="formInline.userfor" placeholder="请选择">
          <el-option
            v-for="type in userfor"
            :label="type.key"
            :value="type.value"
            :key="type.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </el-form-item>
      <el-form-item>
        <el-button
          size="small"
          type="success"
          icon="el-icon-plus"
          @click="$router.push({path:'/exam/paper/edit'})"
        >添加</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table
      size="small"
      :data="mylistData"
      highlight-current-row
      v-loading="loading"
      border
      element-loading-text="拼命加载中"
      style="width: 100%;"
    >
      <el-table-column align="center" type="index" width="60"></el-table-column>
      <el-table-column sortable prop="id" label="试卷编号" width="120" show-overflow-tooltip></el-table-column>
      <el-table-column sortable prop="paperName" label="试卷名称" width="120" show-overflow-tooltip></el-table-column>
      <el-table-column sortable prop="userfor" label="用途" width="120" show-overflow-tooltip></el-table-column>//
      <el-table-column sortable prop="total" label="总分" width="140" show-overflow-tooltip></el-table-column>
      <el-table-column sortable prop="name" label="创建人" width="120" show-overflow-tooltip></el-table-column>
      <el-table-column sortable prop="createTime" label="创建时间" width="120" show-overflow-tooltip></el-table-column>
      <el-table-column align="center" label="操作" min-width="150">
        <template slot-scope="scope">
          <el-tooltip effect="dark" content="查看详情" placement="bottom">
            <el-button
              size="mini"
              type="success"
              @click="handleEdit(scope.$index, scope.row)"
              icon="el-icon-view"
            ></el-button>
          </el-tooltip>
          <el-tooltip effect="dark" content="删除" placement="bottom">
            <el-button
              size="mini"
              type="danger"
              @click="deletePaper(scope.$index, scope.row)"
              icon="el-icon-delete"
            ></el-button>
          </el-tooltip>
          <el-tooltip effect="dark" content="修改" placement="bottom">
            <el-button
              size="mini"
              type="warning"
              @click="$router.push({path:'/exam/paper/edit',query:{id:scope.row.id}})"
              icon="el-icon-edit"
            ></el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @call="callFather"></Pagination>
    <!-- 编辑界面 -->
    <el-dialog
      :title="title"
      :visible.sync="editFormVisible"
      width="50%"
      @click="closeDialog('editForm')"
    >
      <div style="text-align">
        <h3>{{paperName}}</h3>
      </div>
      <el-form>
        <el-card class="box-card" v-for="(question,index) in questions" :key="index">
          <div v-if="question.type==1">
            <div>第{{index+1}}题 {{question.title}}</div>
            <el-radio-group v-model="singleOption">
              <div v-for="(o,index) in question.optionList" :key="index" class="text item">
                <el-radio disabled :label="index">{{o.content }}</el-radio>
              </div>
            </el-radio-group>
          </div>
          <div v-if="question.type==2">
            <div>第{{index+1}}题 {{question.title}}</div>
            <el-checkbox-group v-model="mutipleOption">
              <div v-for="(o,index) in question.optionList" :key="index" class="text item">
                <el-checkbox disabled :label="index">{{o.content }}</el-checkbox>
              </div>
            </el-checkbox-group>
          </div>
          <div v-if="question.type==3">
            <div>
              第{{index+1}}题 {{question.title}}
              <el-radio disabled v-model="judgeOption" label="T"></el-radio>
              <el-radio disabled v-model="judgeOption" label="F"></el-radio>
            </div>
          </div>
          <div v-if="question.type==4">
            <div>第{{index+1}}题 {{question.title}}</div>
          </div>
          <div v-if="question.type==5">
            <div>第{{index+1}}题 {{question.title}}</div>
          </div>
        </el-card>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import Pagination from "@/components/Pagination";
export default {
  data() {
    return {
      singleOption: [],
      mutipleOption: [],
      judgeOption: "T",
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: "预览",
      userfor: [
        { key: "请选择", value: 0 },
        { key: "测评试卷", value: 1 },
        { key: "模拟试卷", value: 2 },
      ],
      formInline: {
        page: 1,
        limit: 10,
        paperName: "",
        userfor: 0,
        token: localStorage.getItem("logintoken"),
      },
      // 删除部门
      seletedata: {
        ids: "",
        token: localStorage.getItem("logintoken"),
      },
      userparm: [], //搜索权限
      mylistData: [], //用户数据
      paperName: "", //试卷名称
      questions: [],
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10,
      },
    };
  },
  // 注册组件
  components: {
    Pagination,
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.search();
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    getData() {
      this.$axios
        .get("http://localhost:8081/Paper/selectAll", {
          params: {
            startpage: this.pageparm.currentPage,
            pagesize: this.pageparm.pageSize,
          },
        })
        .then((res) => {
          console.log(res.data.list);
          this.pageparm.total = res.data.total;
          this.mylistData = res.data.list;
          this.mylistData.forEach((s) => {
            if (s.userfor == 1) {
              s.userfor = "测评试卷";
            } else {
              s.userfor = "模拟试卷";
            }
          });
        })
        .catch((err) => {});
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage;
      this.formInline.limit = parm.pageSize;
      this.pageparm.currentPage = parm.currentPage;
      this.pageparm.pageSize = parm.pageSize;
      this.search();
    },
    // 搜索事件
    search() {
      this.$axios
        .post("http://localhost:8081/Paper/queryPaper", {
          startpage: this.pageparm.currentPage,
          pagesize: this.pageparm.pageSize,
          paper: {
            paperName: this.formInline.paperName,
            userfor: this.formInline.userfor,
          },
        })
        .then((res) => {
          console.log(res);
          this.mylistData = res.data.list;
          this.pageparm.total = res.data.total;
          this.mylistData.forEach((s) => {
            if (s.userfor == 1) {
              s.userfor = "测评试卷";
            } else if (s.userfor == 2) {
              s.userfor = "模拟试卷";
            }
          });
        })
        .catch((err) => {});
    },
    //显示编辑界面
    handleEdit: function (index, row) {
      console.log(index);
      console.log(row);
      this.editFormVisible = true;
      this.$axios
        .get("http://localhost:8081/Paper/showPaperView", {
          params: {
            id: row.id,
          },
        })
        .then((res) => {
          console.log(res);
          this.paperName = res.data.paper.paperName;
          this.questions = res.data.questions;
        })
        .catch((err) => {});
    },
   
    // 删除试卷
    deletePaper(index, row) {
      this.$confirm("确定要删除吗?", "信息", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$axios
            .get("http://localhost:8081/Paper/deletePaper?id=" + row.id)
            .then((res) => {
              if (res.data == "success") {
                this.$message({
                  type: "success",
                  message: "试卷已删除!",
                });
                this.search();
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 关闭编辑、增加弹出框
    closeDialog(formName) {
      this.editFormVisible = false;
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style scoped>
.paper-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
.text {
  font-size: 14px;
}

.item {
  padding: 10px 0;
}

.box-card {
  width: auto;
  margin-top: 20px;
}
</style>

 
 

 